package com.zj.osm.utils;

import android.util.Log;

import com.google.android.gms.maps.model.LatLng;

import java.text.DecimalFormat;

/**
 * 计算两经纬度之间的角度
 */
public class AngleUtil {

    /**
     * 求B点经纬度
     * @param A 已知点的经纬度，
     * @param distance   AB两地的距离  单位km
     * @param angle  AB连线与正北方向的夹角（0~360）
     * @return  B点的经纬度
     */
    private final static double Rc=6378137;
    private final static double Rj=6356725;
    private double m_RadLo,m_RadLa;
    private double Ec;
    private double Ed;
    public AngleUtil(double longitude, double latitude){
        m_RadLo=longitude* Math.PI/180.;
        m_RadLa=latitude* Math.PI/180.;
        Ec=Rj+(Rc-Rj)*(90.- latitude)/90.;
        Ed=Ec* Math.cos(m_RadLa);
    }


    public static LatLng getMyLatLng(AngleUtil A, double distance, double angle){
        double dx = distance* Math.sin(Math.toRadians(angle));
        double dy= distance* Math.cos(Math.toRadians(angle));
        double bjd=(dx/A.Ed+A.m_RadLo)*180./ Math.PI;
        double bwd=(dy/A.Ec+A.m_RadLa)*180./ Math.PI;
        return new LatLng(bwd,bjd);
    }

    public static void main(String[] args) {
        double ttB = (6*6 +6*6 -6*6.0 )/ (2 * 6 * 6);
        System.out.println(ttB);
        double angles = Math.acos(ttB);
        System.out.println(angles);
        double result= 180 / Math.PI *angles;
        System.out.println(result);

    }
}